#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 19-5-29 上午12:30
# @Author  : Tom
# @Site    : 
# @File    : get_qq_infor.py
# @Software: PyCharm


from django.conf import settings
from urllib.parse import urlencode, parse_qs
import json
import requests


# 获取user信息
def get_user_infor(access_token, app_id, open_id):
    # 构建请求url
    url = 'https://graph.qq.com/user/get_user_info?access_token=' + access_token + '&oauth_consumer_key=' + app_id + '&openid=' + str(open_id)
    # 发送请求
    try:
        response = requests.get(url)
        # 提取数据
        data = response.text
    except:
        raise Exception('qq请求失败')
    # 转化为字典
    try:
        data_dict = json.loads(data)
    except:
        raise Exception('user_infor获取失败')
    return data_dict